package com.spzx.product.api.fallback;

import com.spzx.common.core.domain.R;
import com.spzx.product.api.CategoryFeignClient;
import com.spzx.product.api.domain.vo.CategoryVo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

/**
 * @ClassName CategoryFeignClientFallbackFactory
 * @Author 波
 * @Date 2024/8/4 11:00
 */
public class CategoryFeignClientFallbackFactory implements FallbackFactory<CategoryFeignClient> {

    private static final Logger log = LoggerFactory.getLogger(CategoryFeignClientFallbackFactory.class);
    @Override
    public CategoryFeignClient create(Throwable cause) {
        log.error("商品服务调用失败:{}", cause.getMessage());
        return new CategoryFeignClient() {
            @Override
            public R<List<CategoryVo>> getOneCategory(String source) {
                return R.fail("获取全部一级分类失败:" + cause.getMessage());
            }

            @Override
            public R<List<CategoryVo>> getCategoryTree(String source) {
                return R.fail("获取分类列表信息失败:" + cause.getMessage());
            }
        };
    }
}
